importJar('redis.clients:jedis:jar:3.0.1');
importClass("redis.clients.jedis.Jedis");

var baseProperties = importProperties("classpath:/script.redis.properties");

/**
 * 实现创建方法.
 * @param host host.
 * @param port port.
 * @param password pwd.
 * @returns {Jedis} 对象.
 */
function newRedis(host, port, password) {
    console.info("newRedis, host=" + host + ", port=" + port + (password ? " ,password=******" : ""));
    var redis = new Jedis(host, parseInt(port));
    if (null != password && !util.isBlank(password)) {
        redis.auth(password);
    }
    return redis;
}

/**
 * 快速创建redis对象.
 * @param envKey key.
 */
function createRedis(envKey) {
    var host = baseProperties.getProperty(envKey + ".host");
    var port = baseProperties.getProperty(envKey + ".port");
    var password = baseProperties.getProperty(envKey + ".password");
    return newRedis(host, port, password);
}